package com.itheima.service.impl;


import com.itheima.controller.Code;
import com.itheima.dao.CarDao;
import com.itheima.domain.Car;
import com.itheima.exception.BusinessException;
import com.itheima.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarDao carDao;
    @Override
    public boolean save(Car car) {
        carDao.save(car);
        return true;
    }

    @Override
    public boolean update(Car car) {
        carDao.update(car);
        return true;
    }

    @Override
    public boolean delete(Integer id) {
        carDao.delete(id);
        return true;
    }

    @Override
    public Car getById(Integer id) {
        //模拟业务异常，包装成自定义异常
        if(id <0){
            throw new BusinessException(Code.BUSINESS_ERR,"请不要使用你的技术挑战我的耐性!");
        }
        return carDao.getById(id);
    }

    @Override
    public List<Car> getAll() {
        return carDao.getAll();
    }
}
